package ms;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class RegistrationDay {

	public static void main(String[] args) {
		int studentNumber, officeNumber;
		int moveCost;
		Scanner scanner = new Scanner(System.in);
		long sid;
		int reachOffice;
		List<Integer> list;
		int reachTime;  //到达校门的时间
		int office, spentTime;
		List<OfficeTime> officeList= new ArrayList<>();
		List<Student> list2 = new ArrayList<>();
		while(scanner.hasNext()){
			studentNumber = scanner.nextInt();
			officeNumber = scanner.nextInt();
			moveCost = scanner.nextInt();
			for (int i = 0; i < studentNumber; i++) {
				sid = scanner.nextLong();
				reachTime = scanner.nextInt();
				reachOffice = scanner.nextInt();
				for (int j = 0; j < reachOffice; j++) {
					office = scanner.nextInt();
					spentTime = scanner.nextInt();
					OfficeTime time = new OfficeTime(office, spentTime, reachTime + moveCost);
					reachTime = reachTime + spentTime;
					officeList.add(time);
				}
				list2.add(new Student(sid, officeList));
			}
			
			//之后以到达房间的时间为触发事件，来进行模拟
			OfficeTime lastOfficeTime ;
			for (Student student : list2) {
				lastOfficeTime = student.reachTime.get(student.reachTime.size() - 1);
				System.out.println(lastOfficeTime.reachTime + lastOfficeTime.spentTime);
			}
		}
		scanner.close();
	}
	
	public static class Student{
		public long sid;
		public List<OfficeTime> reachTime;
		public Student(long sid, List<OfficeTime> reachTime) {
			this.sid = sid;
			this.reachTime = reachTime;
		}
	}
	public static class OfficeTime{
		int officeNumber;
		int spentTime;
		int reachTime;
		public OfficeTime(int office, int spent, int reach) {
			officeNumber = office;
			spentTime = spent;
			this.reachTime = reach;
		}
	}
}
